#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

ll gcd(ll a,ll b){
    if(b==0)return a;
    else return gcd(b,a%b);
}

vector<ll>fac;

void solve(){
    ll x,y;
    cin>>x>>y;
    ll gcdxy=gcd(x,y);
    ll lcmxy=(x*y)/gcd(x,y);
    ll temp=lcmxy/gcdxy;
    ll wai=1LL,li=1LL;
    for(int i=0;i<fac.size();i++){
        if(fac[i]>temp)break;
        while(temp%(fac[i]*fac[i])==0){
            temp/=fac[i]*fac[i];
            wai*=fac[i];
        }
    }
    cout<<wai<<" "<<temp<<endl;
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    vector<bool> isprime(1e5+5,true);
    for(ll i=2LL;i<=1e5;i++){
        if(isprime[i])fac.push_back(i);
        for(int j=0;j<fac.size();j++){
            isprime[fac[j]*i]=false;
            if(i%fac[j]==0)break;
        }
    }
    int _=1;
    cin>>_;
    cout<<fac.size();
    while(_--){
        solve();
    }
    return 0;
}